<?php
namespace app\shop\controller\admin;

use app\admin\library\AdminController;


class Field extends AdminController
{
    public function onGooodsTagGroupOption(){
        $GoodsTagGroup =  $this->model('GoodsTagGroup');
        $GoodsTagGroup->where('cold',0); 
        return $GoodsTagGroup->order('sort','desc')->getData();
    }

    public function onGoodsTagList(){
        $group_id = $this->post('group_id',$this->check()->type('int'));
       
        $page = $this->post('page',$this->check()->type('int')->default(1));
        
        $GoodsTag =  $this->model('GoodsTag');
        if ($group_id){
            $GoodsTag->where('group_id',$group_id);
        }

        $GoodsTag->order('tag_id','desc');
        $list = $GoodsTag->page($page,40)->getData();
        return ['list'=>$list,'total'=>$GoodsTag->total,'pageCount'=>$GoodsTag->pageCount];
    }

    public function onModelOption(){
        $type = $this->post('type',$this->check()->type('string'));
      
        $model = $this->model('Model');
    

        $model->where('type','<>','globalparam');
        $model->where('cold',0); 
        
        if ($type){
            $model->where('type',$type);
        }
    
        return $model->getData();
    }


    public function onSpecOption(){
        $model = $this->model('Spec');
        $model->where('cold',0); 
        return $model->order('spec_id','ASC')->getData();
    }

    public function onVariantOption(){
        $variant =  $this->model('Variant');
        $variant->where('cold',0); 
        return $variant->getData();
    }


    public function onPageList(){
        $pageCurrent = $this->post('page',$this->check()->type('int')->default(1));
        $page = $this->model('Page');
        
        $page->where('cold',0); 
        
        $list = $page->page($pageCurrent,20)->getData();
        foreach($list as &$v){
            $v['create_time'] = date('Y-m-d',$v['create_time']);
            unset($v['design_content']);
        }

        return ['list'=>$list,'total'=>$page->total,'count'=>$page->pageCount];
    }


    public function onGoodsList(){
        $ids =  $this->post('ids',$this->check()->type('string'));

        $goods =  $this->model('Goods');
        $goods->where('goods_id','in',explode(',',$ids));
        
        return $goods->getData();
    }

}